//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.cloud.logger.zchain.spring.config;

import com.cloud.logger.zchain.core.InetAddressUtilities;
import com.cloud.logger.zchain.core.common.entity.AngelaLoggerProjectNode;
import com.cloud.logger.zchain.core.common.properties.ServerInfo;
import com.cloud.logger.zchain.core.common.threadlocal.LoggerThreadLocal;
import com.cloud.logger.zchain.core.zookeeper.ZookeeperFactory;
import com.cloud.logger.zchain.spring.properties.ZchainProperties;
import com.cloud.logger.zchain.zchainclient.util.AngelaAopLogger;
import com.cloud.logger.zchain.zchainclient.util.KafkaUtil;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Timer;
import java.util.TimerTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

@Configuration
@EnableConfigurationProperties({ZchainProperties.class})
public class ZchainClientSpringBootInit implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
    @Autowired
    private ZchainProperties zchainProperties;
    private static EmbeddedServletContainerInitializedEvent event;

    public ZchainClientSpringBootInit() {
    }

    public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
        this.event = event;
        this.initServer();
        this.initTask();
    }

    private void initServer() {
        try {
            ServerInfo.setScenic(this.zchainProperties.getProject().getScenic());
            ServerInfo.setProject(this.zchainProperties.getProject().getName());
            ServerInfo.setIp(InetAddressUtilities.getLocalHostLANAddress().getHostAddress());
            ServerInfo.setPort(event.getEmbeddedServletContainer().getPort());
            String success = this.zchainProperties.getCode().getSuccess();
            if (!StringUtils.isEmpty(success)) {
                String[] codeArr = success.split(",");
                AngelaAopLogger.RESULT_SUCCESS = new HashSet(Arrays.asList(codeArr));
            }

            String code = this.zchainProperties.getCode().getName();
            AngelaAopLogger.RESULT_CODE = StringUtils.isEmpty(code) ? AngelaAopLogger.RESULT_CODE : code;
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }

    public void initTask() {
        KafkaUtil.startProject();
        AngelaLoggerProjectNode project = LoggerThreadLocal.getCurrentProject();
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            public void run() {
                KafkaUtil.checkKafka();
            }
        }, 60000L, 600000L);
        ZookeeperFactory zookeeperFactory = ZookeeperFactory.getInstance();

        try {
            zookeeperFactory.init("115.159.160.97:2181", "zchain-client", 5000);
        } catch (Exception var6) {
            var6.printStackTrace();
        }

        try {
            zookeeperFactory.createProjectNode(project);
        } catch (Exception var5) {
            var5.printStackTrace();
        }

    }
}
